﻿import _ from 'lodash';

// 基础路由
export const baseRoute = [
  {
    name: '登录',
    path: '/login',
    layout: false,
    component: './user/login',
  },
  {
    path: '/403',
    component: './403',
  },
  {
    component: './404',
  },
];

/**
 * 动态路由
 * path: string; 路径不能重复，通配符路径的规则同样不能重复；带有通配符的页面可实现切换子路径在路由页面不刷新情况下完成内部组件间的跳转，最终只有一个路由页面。
 * shareWithParamsKey?: string; // 通用页面使用该字段表示获取资源节点sourceParams下的值作为子路径，path需要配置通配符，最终以多个子路由页面形式存在。
 * component: string; // 页面路径
 * description?: string; // 页面描述（菜单编辑表单的页面地址选择悬浮提示）
 */
export const dynamicRoute = [
  {
    path: '/index',
    description: '首页',
    component: './index',
  },
  {
    path: '/welcome',
    description: '欢迎页（测试用）',
    component: './welcome',
  },
  // 任务中心
  {
    path: '/workCenter/taskSummary',
    description: '任务汇总',
    component: './workCenter/taskSummary',
  },
  {
    path: '/workCenter/taskStart/*',
    description: '发起流程',
    component: './workCenter/taskStart',
  },
  {
    path: '/workCenter/taskAction',
    description: '待办/待审批',
    component: './workCenter/taskAction',
  },
  // 在线开发
  {
    path: '/online/onlinePage/onlinePageDesign',
    description: '在线页面设计',
    component: './online/onlinePage/onlinePageDesign',
  },
  {
    path: '/online/onlinePage/onlinePageManager',
    description: '在线页面管理',
    component: './online/onlinePage/onlinePageManager',
  },
  {
    path: '/online/onlineWork/onlineWorkDesign',
    description: '在线流程设计',
    component: './online/onlineWork/onlineWorkDesign',
  },
  {
    path: '/online/onlineWork/onlineWorkManager',
    description: '在线流程管理',
    component: './online/onlineWork/onlineWorkManager',
  },
  {
    path: '/online/onlineWork/onlineWorkFormDesign',
    description: '流程表单设计',
    component: './online/onlineWork/onlineWorkFormDesign',
  },
  {
    path: '/online/onlineWork/onlineWorkFormManager',
    description: '流程表单管理',
    component: './online/onlineWork/onlineWorkFormManager',
  },
  {
    path: '/online/onlineReport/onlineReportDesign',
    description: '在线报表设计',
    component: './online/onlineReport/onlineReportDesign',
  },
  {
    path: '/online/onlineReport/onlineReportManager',
    description: '在线报表管理',
    component: './online/onlineReport/onlineReportManager',
  },
  // 系统管理
  {
    path: '/system/user',
    description: '用户管理',
    component: './system/user',
  },
  {
    path: '/system/role',
    description: '角色管理',
    component: './system/role',
  },
  {
    path: '/system/department',
    description: '机构部门管理',
    component: './system/department',
  },
  {
    path: '/system/job',
    description: '岗位管理',
    component: './system/job',
  },
  {
    path: '/system/resource',
    description: '资源管理',
    component: './system/resource',
  },
  {
    path: '/system/dict/*',
    description: '字典管理',
    component: './system/dictionary',
  },
  {
    path: '/system/responseCode',
    description: '响应码管理',
    component: './system/responseCode',
  },
  {
    path: '/system/configuration',
    description: '配置管理',
    component: './system/configuration',
  },
  {
    path: '/system/logs',
    description: '日志管理',
    component: './system/logs',
  },
  // 个人中心
  {
    path: '/personal/setting',
    description: '个人信息设置',
    component: './personalCenter/setting',
  },
  // 应用集成
  {
    path: '/application/microApp',
    description: '微前端集成',
    component: './application/microApp',
  },
  {
    path: '/application/outPage',
    description: '外链H5集成',
    component: './application/outPage',
  },
  {
    path: '/application/platformManager',
    description: '线上平台同步',
    component: './application/platformManager',
  },
  // 通用容器页面
  {
    path: '/design/*',
    description: '通用设计页面渲染，在页面管理配置激活',
    shareWithParamsKey: 'pageId', // 通用页面, 取sourceParams的pageId字段作为二级路径
    component: '@/components/CommonPages/designPage',
  },
  {
    path: '/report/*',
    description: '通用报表页面，需配置报表code',
    shareWithParamsKey: 'categoryCode', // 通用页面, 取sourceParams的categoryCode字段作为二级路径
    component: '@/components/CommonPages/report',
  },
  {
    path: '/outPage/*',
    description: '通用外链页面，需配置页面url',
    shareWithParamsKey: 'sourceUrl', // 通用页面, 取sourceParams的sourceUrl字段作为二级路径
    component: '@/components/CommonPages/outPage',
  },
];

// 添加动态路由的权限校验（校验文件地址：src/permission）
const addAccess: any = (list: any) => {
  _.forEach(list, (item) => {
    item.wrappers = ['@/permission'];
  });
  return list;
};

export default [
  {
    path: '/',
    component: '@/components/RouteTransferWrapper',
    routes: [...addAccess(dynamicRoute), ...baseRoute],
  },
];
